<template>
  <div style="margin: 10px">
    <el-button type="primary" style="margin: 10px" @click="cancel">返回</el-button>
    <div>
      <el-card>
        <el-form ref="form" style="padding: 10px" :model="deviceForm">
          <el-form-item label="设备标识">
            <el-input v-model="deviceForm.identification" placeholder="设备标识" style="width: 500px" />
          </el-form-item>
          <el-form-item label="设备名称">
            <el-input v-model="deviceForm.name" placeholder="设备名称" style="width: 500px" />
          </el-form-item>
          <el-form-item label="设备位置">
            <el-input v-model="deviceForm.location" placeholder="设备位置" style="width: 500px" />
          </el-form-item>
          <el-form-item label="设备描述">
            <el-input v-model="deviceForm.description" placeholder="设备描述" style="width: 500px" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="adddevice()">保存</el-button>
            <el-button @click="cancel">取消</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Equop',
  props: {
    companyid: String
  },
  data() {
    return {
      // 设备添加表单
      deviceForm: {
        identification: '',
        name: '',
        location: '',
        description: '',
        company_id: ''
      }
    }
  },
  methods: {
    cancel() {
      this.$emit('changeScene', 1)
      Object.assign(this._data, this.$options.data())
    },
    adddevice() {
      this.$axios.post(this.PlatformBaseURL + '/device/add',
        {
          identification: this.deviceForm.identification,
          name: this.deviceForm.name,
          location: this.deviceForm.location,
          description: this.deviceForm.description,
          company_id: parseInt(this.companyid)
        },
        {
          headers: {
            satoken: window.localStorage.getItem('token')
          }
        }
      ).then((res) => {
        if (res.code === 200) {
          this.$message({
            message: '添加设备成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '添加设备失败:' + res.msg,
            type: 'error'
          })
        }
        this.$emit('changeScene', 1)
        this.$parent.getEquList()
      }
      )
    }
  }
}
</script>

<style scoped>

</style>
